<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">

<div id="id_panel">
</div>
<script th:inline="javascript">
	var dto = $.parseJSON(JSON.stringify([[${dto}]]));
	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
				form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal;
		/*
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
				{
					id:'id_panel', // 页面容器ID
					dto: $.parseJSON(JSON.stringify([[${dto}]]))
				}
		);

		$('#' + formObj.c.id_header).find('.bg_color_white').find('.layui-inline').append('<button type="button" class="layui-btn layui-btn-normal" id="logisticsDetails" lay-submit onclick="uploadLogistics()">物流方式详情</button>');
		$('#' + formObj.c.id_header).find('.bg_color_white').find('.layui-inline').append('<button type="button" class="layui-btn layui-btn-normal" id="costsDetails" lay-submit onclick="uploadCosts()">预估费用详情</button>');

		if (dto.valueMap.creationMethod == 1){
			var domForm = $('#' + formObj.c.id_form);
			var dom = domForm.find('input[name="evenlyBoxNum"]');
			dom.prop('disabled', false);
			dom.prop('class', 'layui-input height_30 height_30');
		}
		form.on('select(_input_filter_selector_on_form)', function(data) {
			var name = $(data.elem).attr('name');
			var t = formObj;
			var domForm = $('#' + t.c.id_form);
			if (name == 'creationMethod'){
				//监听下单方式
				var creationMethod = formObj.getValueByName("creationMethod");
				if (creationMethod == '1'){
					layer.alert("该货件为自动发货，系统将自动传输数据至店铺后台，该制单至追踪编码上传前都不可在后台手工终止，否则货件将无效！")
					var dom = domForm.find('input[name="evenlyBoxNum"]');
					dom.prop('disabled', false);
					dom.prop('class', 'layui-input height_30 height_30');
				}else if (creationMethod == '0') {
					var dom = domForm.find('input[name="evenlyBoxNum"]');
					dom.prop('disabled', true);
					dom.prop('class', 'layui-input height_30 height_30 cannot_edit');
					dom.val(0)
				}
			}
		});

		formObj.matchValuesAfterModalSelectRadio = function(colCode, rowSelected, extraData) {
			var t = formObj;
			var domForm = $('#' + t.c.id_form);
			for(var i = 0; i < t.c.dto.rows.length; i++){
				var col = t.c.dto.rows[i];
				if (col.code == colCode) {
					// 给选择框设置的字段赋值
					domForm.find('input[name="' + colCode + '"]').val(rowSelected[col.modalValueCode]);
				} else if(col.modalRelativeCode == colCode) {
					domForm.find('input[name="' + col.code + '"]').val(rowSelected[col.modalValueCode]);
				}
			}
			if (colCode == "shopName"){
				formObj.setValueByName("logsticsWay",null)
				formObj.setValueByName("logsticsWayId",null)
			}
			formObj.c.subGridObj.clearRows();
		};

		//重写弹出框
		formObj.showModal=function(modalKey, colCode) {
			var t = formObj;
			if(colCode == 'logsticsWay'){//物流方式弹框
				var shopName = formObj.getValueByName("shopName");//网店名称
				var shopId = formObj.getValueByName("shopId");//网店Id
				var vgsbm = formObj.getValueByName("vgsbm");//运营公司编码
				if(shopName != null){
					layui.YsModal.init({modalKey: modalKey, colCode: colCode, parentObj: t, extraData:{}, conditionsDefault: [], sameCode: 'xx'
						,pathGridRequest: '/api/inter/tccLogisticsMethod/searchFbaPlan?shopId='+shopId+"&vgsbm="+vgsbm});
				}else {
					return layer.msg("网店名称不允许为空!");
				}
			} else{
				// 打开单选框,
				layui.YsModal.init({modalKey: modalKey, colCode: colCode, parentObj: t, extraData:{}, conditionsDefault: [{code: 'aaa', value:'123'},{code: 'bbb', value:'456'}], sameCode: 'xx'});
			}
		}

	});


	function uploadLogistics() {
		var bid = formObj.getValueByName("bid");
		var w=($(window).width());
		var h=($(window).height());
		layer.open({
			title:'物流方式 - 详情',
			type: 2,
			area: [w+'px', h +'px'],
			fix: true,
			maxmin: false,
			shadeClose: true,
			shade:0.4,
			content:'/web/storage/tccFbaPlan/toEditWl?bid=' + bid});

	}

	function uploadCosts() {
		var bid = formObj.getValueByName("bid");
		var bid = formObj.getValueByName("bid");
		var w=($(window).width());
		var h=($(window).height());
		layer.open({
			title:'预估费用 - 详情',
			type: 2,
			area: [w+'px', h +'px'],
			fix: true,
			maxmin: false,
			shadeClose: true,
			shade:0.4,
			content:'/web/storage/tccFbaPlan/toEditFee?bid=' + bid});
	}
</script>



</body>
</html>